<template>
  <el-row class="mod-config">
    <el-card>
      <el-form :inline="true" :model="dataForm" ref="linesearchform" @keyup.enter.native="getDatalineList()">
        <el-row>
          <el-form-item class="el-col-7" prop="lineNumber" label="线路编号">
            <el-input v-model="dataForm.lineNumber" placeholder="线路编号" clearable></el-input>
          </el-form-item>
          <el-form-item class="el-col-7" prop="name" label="线路名称">
            <el-input v-model="dataForm.name" placeholder="线路名称" clearable></el-input>
          </el-form-item>
          <el-form-item class="el-col-7" prop="transportLineTypeId" label="线路类型">
            <el-select v-model="dataForm.transportLineTypeId" placeholder="线路类型">
              <el-option label="请选择" value="0" aria-selected="true" ></el-option>
              <el-option
                v-for="item in ltlist"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button class="el-button--primary" @click="getDatalineList()">查询</el-button>
            <el-button class="el-button--warning" @click="lineresetdateform('linesearchform')">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-card>

    <el-card>
      <el-row>
        <el-button class="el-button--success" @click="addlineVisible = true">+新增线路</el-button>
      </el-row><br>
      <el-table
        :data="datalineList"
        border
        v-loading="datalineListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <el-table-column type="expand" prop="transportTrips">
          <template slot-scope="scope">
            <el-table
              :data="scope.row.transportTrips"
              style="width: 100%">
              <el-table-column
                prop="name"
                label="车次名称"
                width="180">
              </el-table-column>
              <el-table-column
                prop="period"
                label="发车频次"
                width="180">
              </el-table-column>
              <el-table-column
                prop="departureTime"
                label="发车时间"
                width="180">
              </el-table-column>
              <el-table-column
                prop="truckdriver"
                label="车辆司机安排"
                width="180">
              </el-table-column>
              <el-table-column
                prop=""
                label="操作"
                width="300">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="gettripsbyid(scope.row.id)">编辑车次</el-button>&nbsp;
                  <el-button type="text" size="small" @click="deletetrips(scope.row.id)">删除</el-button>
                  <el-button type="text" size="small" @click="maketrucks(scope.row.id)">安排车辆</el-button>&nbsp;
                  <el-button type="text" size="small" @click="makedriver(scope.row.id)">安排司机</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column><!---->
        <el-table-column
          prop="lineNumber"
          header-align="center"
          align="center"
          label="线路编号">
        </el-table-column>
        <el-table-column
          prop="name"
          header-align="center"
          align="center"
          label="线路名称">
        </el-table-column>
        <el-table-column
          prop="transportLinename"
          header-align="center"
          align="center"
          label="线路类型">
        </el-table-column>
        <el-table-column
          prop="startAgencyname"
          header-align="center"
          align="center"
          label="起始地机构">
        </el-table-column>
        <el-table-column
          prop="endAgencyname"
          header-align="center"
          align="center"
          label="目的地机构">
        </el-table-column>
        <el-table-column
          prop="distance"
          header-align="center"
          align="center"
          label="距离（千米）">
        </el-table-column>
        <el-table-column
          prop="cost"
          header-align="center"
          align="center"
          label="成本（元）">
        </el-table-column>
        <el-table-column
          prop="estimatedTime"
          header-align="center"
          align="center"
          label="预计时间（分钟）">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="260"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-location-outline" size="small" @click="getbaiduditu(scope.row.id)">地图</el-button>&nbsp;&nbsp;&nbsp;
            <el-button type="text" size="small" @click="getlineinfo(scope.row.id)">修改</el-button>&nbsp;
            <el-button type="text" style="color: red" size="small" @click="deleteline(scope.row.id)">删除</el-button>&nbsp;
            <el-button type="text" size="small" @click="addtripsbyid(scope.row.id)">增加车次</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-card>


    <el-dialog custom-class="addlinewidth" title="新增线路" :visible.sync="addlineVisible" :close-on-click-modal="false">

      <el-tabs type="border-card">
        <el-form ref="addlineform" label-width="100px">
          <el-row>
            <el-form-item prop="lineNumber" label="线路编号">
              <el-input v-model="addlineform.lineNumber" placeholder="线路编号" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="name" label="线路名称">
              <el-input v-model="addlineform.name" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="transportLineTypeId" label="线路类型">
              <el-select v-model="addlineform.transportLineTypeId" placeholder="线路类型">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option
                  v-for="item in ltlist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
              <el-form-item prop="startAgencyId" label="起始地机构">
                <el-select v-model="addlineform.startAgencyId" placeholder="线路类型">
                  <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                  <el-option
                    v-for="item in aglist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-row>
          <el-row>
              <el-form-item prop="endAgencyId" label="目的地机构">
                <el-select v-model="addlineform.endAgencyId" placeholder="线路类型">
                  <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                  <el-option
                    v-for="item in aglist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="distance" label="距离">
              <el-input v-model="addlineform.distance" placeholder="距离" clearable>
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px;">千米</i>
              </el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="cost" label="成本">
              <el-input v-model="addlineform.cost" placeholder="成本" clearable>
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px;">元</i>
              </el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="estimatedTime" label="预计时间">
              <el-input v-model="addlineform.estimatedTime" placeholder="预计时间" clearable>
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px;">分钟</i>
              </el-input>
            </el-form-item>
          </el-row>
        </el-form>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addlineSubmit()">保存</el-button>
        <el-button @click="addlineVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog custom-class="addlinewidth" title="修改线路" :visible.sync="updatelineVisible" :close-on-click-modal="false">

      <el-tabs type="border-card">
        <el-form ref="updatelineform"  label-width="100px">
          <el-row>
            <el-form-item hidden prop="id" label="线路编号">
              <el-input v-model="updatelineform.id" placeholder="线路编号" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="lineNumber" label="线路编号">
              <el-input v-model="updatelineform.lineNumber" placeholder="线路编号" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="name" label="线路名称">
              <el-input v-model="updatelineform.name" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="transportLineTypeId" label="线路类型">
              <el-select v-model="updatelineform.transportLineTypeId" placeholder="线路类型">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option
                  v-for="item in ltlist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="startAgencyId" label="起始地机构">
              <el-select v-model="updatelineform.startAgencyId" placeholder="起始地机构">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option
                  v-for="item in aglist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="endAgencyId" label="目的地机构">
              <el-select v-model="updatelineform.endAgencyId" placeholder="目的地机构">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option
                  v-for="item in aglist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="distance" label="距离">
              <el-input v-model="updatelineform.distance" placeholder="距离" clearable>
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px;">千米</i>
              </el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="cost" label="成本">
              <el-input v-model="updatelineform.cost" placeholder="成本" clearable>
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px;">元</i>
              </el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="estimatedTime" label="预计时间">
              <el-input v-model="updatelineform.estimatedTime" placeholder="预计时间" clearable>
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px;">分钟</i>
              </el-input>
            </el-form-item>
          </el-row>
        </el-form>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateline()">确定</el-button>
        <el-button @click="updatelineVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog custom-class="addlinewidth" title="新增车次" :visible.sync="addtripsVisible" :close-on-click-modal="false">

      <el-tabs type="border-card">
        <el-form ref="addtripsforms" label-width="100px">
          <el-row>
            <el-form-item hidden prop="transportLineId" label="线路id">
              <el-input v-model="addtripsform.transportLineId" placeholder="线路id" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="linename" label="线路名称">
              <el-input v-model="addtripsform.linename" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="name" label="车次名称">
              <el-input v-model="addtripsform.name" placeholder="车次名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="departureTime" label="发车时间">
              <el-time-select
                v-model="addtripsform.departureTime"
                placeholder="选择时间">
              </el-time-select>
              <el-select v-model="addtripsform.period" placeholder="选择周期">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option label="天" value="1" ></el-option>
                <el-option label="周" value="2" ></el-option>
                <el-option label="月" value="3" ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addtripsSubmit()">保存</el-button>
        <el-button @click="addtripsVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog custom-class="addlinewidth" title="修改车次" :visible.sync="updatetripsVisible" :close-on-click-modal="false">

      <el-tabs type="border-card">
        <el-form ref="updatetripsforms" label-width="100px">
          <el-row>
            <el-form-item hidden prop="id" label="车次id">
              <el-input v-model="updatetripsform.id" placeholder="车次id" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item hidden prop="transportLineId" label="线路id">
              <el-input v-model="updatetripsform.transportLineId" placeholder="线路id" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="linename" label="线路名称">
              <el-input readonly v-model="updatetripsform.linename" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="name" label="车次名称">
              <el-input v-model="updatetripsform.name" placeholder="车次名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="departureTime" label="发车时间">
              <el-time-select
                v-model="updatetripsform.departureTime"
                placeholder="选择时间">
              </el-time-select>
              <el-select v-model="updatetripsform.period" placeholder="选择周期">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option label="天" value="1" ></el-option>
                <el-option label="周" value="2" ></el-option>
                <el-option label="月" value="3" ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updatatrips()">确定</el-button>
        <el-button @click="updatetripsVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog custom-class="addlinewidth" title="安排车辆" :visible.sync="maketruckVisible" :close-on-click-modal="false">

      <el-tabs type="border-card">
        <el-form ref="truckforms" label-width="100px">
          <el-row>
            <el-form-item hidden prop="id" label="线路名称">
              <el-input readonly v-model="truckform.id" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="linename" label="线路名称">
              <el-input readonly v-model="truckform.linename" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="name" label="车次名称">
              <el-input v-model="truckform.name" placeholder="车次名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="departureTime" label="发车时间">
              <el-time-select
                v-model="truckform.departureTime"
                placeholder="选择时间">
              </el-time-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="truckId" label="车辆安排">
              <el-select v-model="truckform.truckslist" placeholder="车辆安排">
                <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                <el-option
                  v-for="item in trucklist"
                  :key="item.id"
                  :label="item.licensePlate"
                  :value="item.id">
                  <el-checkbox :key="item.id" v-model="item.check">{{ item.licensePlate }}</el-checkbox>
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="maketrucksubmit()">确定</el-button>
        <el-button @click="maketruckVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="安排司机" :visible.sync="makedriverVisible" :close-on-click-modal="false">

      <el-tabs type="border-card">
        <el-form ref="truckforms" label-width="100px">
          <el-row>
            <el-form-item prop="linename" label="线路名称">
              <el-input readonly v-model="truckform.linename" placeholder="线路名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="name" label="车次名称">
              <el-input v-model="truckform.name" placeholder="车次名称" clearable></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="departureTime" label="发车时间">
              <el-time-select
                v-model="truckform.departureTime"
                placeholder="选择时间">
              </el-time-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="truckId" label="车辆司机安排">
              <el-table
                :data="truckdriverDate"
                style="width: 100%">
                <el-table-column
                  prop="truckname"
                  label="车辆"
                  width="180">
                </el-table-column>
                <el-table-column
                  prop="username"
                  label="司机"
                  width="180">
                  <template slot-scope="scope">
                    <el-select id="drivers" :ref="scope.row.id" v-model="makedriverform.userId" placeholder="司机安排">
                      <el-option label="请选择" value="0" aria-selected="true" ></el-option>
                      <el-option
                        v-for="item in driverlist"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  prop=""
                  label="操作"
                  width="300">
                  <template slot-scope="scope">
                    <el-button id="edit" type="text" size="small" @click="updatetruckdriver(scope.row.id)">编辑</el-button>&nbsp;
                    <el-button id="save" type="text" hidden size="small" @click="makedriversubmit(scope.row.id)">保存</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-row>
        </el-form>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="makedriverVisible = false">确定</el-button>
        <el-button @click="makedriverVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="" :visible.sync="mapVisible" :close-on-click-modal="false">

      <baidu-map :center="center"
                 :zoom="zoom"
                 style="height:600px"
                 scroll-wheel-zoom="scroll-wheel-zoom">
        <!--距离尺-->
        <bm-scale anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-scale>
        <!--        地图转换-->
        <bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_LEFT"></bm-map-type>

        <!--        标记点  -->
        <bm-marker :position="center" animation="BMAP_ANIMATION_BOUNCE">
          <bm-label :content="content" :labelStyle="{color: 'red', fontSize : '12px'}" :offset="{width: -35, height: 30}"/>
        </bm-marker>

      </baidu-map>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="makedriverVisible = false">确定</el-button>
        <el-button @click="mapVisible = false">取消</el-button>
      </div>
    </el-dialog>


  </el-row>
</template>

<style>
.addlinewidth {
  width: 40%;
}
.linedetailswidth{
  width: 80%;
  height: 80%;
}
.noExpand .ant-table-row-expand-icon {

  display: none;

}
</style>

<script src="src/api/work.js"></script>
<script>
import {
  addline,
  addtripsinfo, deletetripsbyid,
  dellinebyid, getdriverinfos,
  getlinedetails,
  getlineinfo,
  getlinetypelist,
  gettripsinfo, gettruckdriverinfo, gettruckinfolist, maketruckdrivers, maketrucks,
  updatelinebyid,
  updatetripsbyid,
} from '../../../api/base'
import {getagency} from '../../../api/agency'

export default {
  data() {
    return {
      dataForm: {
        lineNumber: '',
        name: '',
        transportLineTypeId: '',
      },
      addlineform: {
        lineNumber: '',
        name: '',
        transportLineTypeId: '',
        startAgencyId: '',
        endAgencyId: '',
        distance: '',
        cost: '',
        estimatedTime: '',
      },
      updatelineform: {
        id: '',
        lineNumber: '',
        name: '',
        transportLineTypeId: '',
        startAgencyId: '',
        endAgencyId: '',
        distance: '',
        cost: '',
        estimatedTime: '',
      },
      detaillicensedataForm: {
        id: '',
        engineNumber: '',
        registrationDate: '',
        mandatoryScrap: '',
        overallQuality: '',
        expirationDate: '',
        allowableWeight: '',
        validityPeriod: '',
        transportCertificateNumber: '',
      },
      detailtripsdataForm:{
        tripsransportLine: '',
        tripsname: '',
      },
      pageIndex: 1,
      pageSize: 10,
      totalPage: null,
      datalineListSelections: [],
      addlineVisible: false,
      linedetailsVisible : false,
      datalineList: [],
      datalineListLoading: false,
      datadriverList: [],
      datadriverListLoading: false,
      item: {
        type: '',
        lable: ''
      },
      ltlist: [],
      tabledetailsData: [],
      updatelineVisible: false,
      aglist: [],
      addtripsform: {
        linename: '',
        transportLineId: '',
        name: '',
        departureTime: '',
        period: '',
      },
      updatetripsform: {
        id: '',
        linename: '',
        transportLineId: '',
        name: '',
        departureTime: '',
        period: '',
      },
      addtripsVisible: false,
      updatetripsVisible: false,
      truckform: {
        linename: '',
        name: '',
        departureTime: '',
        truckslist: [],
        transportTripsId: '',
      },
      maketruckVisible: false,
      trucklist: [],
      truckdriverDate: [],
      makedriverVisible: false,
      driverlist: [],
      makedriverform: {
        userId: '',
      },
      mapVisible: false,

      center: {lng: 104.052642, lat:30.587787},
      zoom: 5,
      //覆盖范围半径 分公司为80000  一级转运中心为40000   二级转运中心为20000 网点为5000
      content:"品达物流集团有限公司",

    }
  },
  mounted() {
    this.getDatalineList();
    this.getlinetype();
    this.getagencylist();
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    lineresetdateform() {
      this.$refs['linesearchform'].resetFields();
      this.dataForm.courierid = "请选择";
      this.getDatalineList();
    },
    // 获取数据列表
    getDatalineList() {
      this.datalineListLoading = true
      let params = {
        'pageno': this.pageIndex,
        'pagesize': this.pageSize,
        'lineNumber': this.dataForm.lineNumber,
        'name': this.dataForm.name,
        'transportLineTypeId': this.dataForm.transportLineTypeId,
      }
      getlineinfo(params).then(({data}) => {
          if (data && data.code == 0) {
            this.datalineList = data.line.rows
            this.totalPage = data.line.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        this.datalineListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDatalineList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDatalineList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.datalineListSelections = val
    },

    addlineSubmit() {
      let params = {
        lineNumber: this.addlineform.lineNumber,
        name: this.addlineform.name,
        transportLineTypeId: this.addlineform.transportLineTypeId,
        startAgencyId: this.addlineform.startAgencyId,
        endAgencyId: this.addlineform.endAgencyId,
        distance: this.addlineform.distance,
        cost: this.addlineform.cost,
        estimatedTime: this.addlineform.estimatedTime,
      }
      addline(params).then(({data}) => {
          if (data && data.code == 0) {
            this.$message({
              message: '新增成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.addlineVisible = false
                this.$refs['addlineform'].resetFields()
                this.getDatalineList()
              }
            })
          }
      })

    },
    getlineinfo(id){
      this.updatelineVisible = true;
      getlinedetails(id).then(({data}) => {
        this.updatelineform.id =data.id;
        this.updatelineform.lineNumber =data.lineNumber;
        this.updatelineform.name =data.name;
        this.updatelineform.transportLineTypeId =data.transportLineTypeId;
        this.updatelineform.startAgencyId =data.startAgencyId;
        this.updatelineform.endAgencyId =data.endAgencyId;
        this.updatelineform.distance =data.distance;
        this.updatelineform.cost =data.cost;
        this.updatelineform.estimatedTime =data.estimatedTime;
      })
    },
    updateline(){
      let params = {
        'id' : this.updatelineform.id,
        'lineNumber' : this.updatelineform.lineNumber,
        'name' : this.updatelineform.name,
        'transportLineTypeId' : this.updatelineform.transportLineTypeId,
        'startAgencyId' : this.updatelineform.startAgencyId,
        'endAgencyId' : this.updatelineform.endAgencyId,
        'distance' : this.updatelineform.distance,
        'cost' : this.updatelineform.cost,
        'estimatedTime' : this.updatelineform.estimatedTime,
      }
      updatelinebyid(params).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '修改成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.updatelineVisible = false;
              this.getDatalineList()
            }
          })
        }
      })
    },
    deleteline(id){
      dellinebyid(id).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '删除成功',
            type: 'error',
            duration: 1500,
            onClose: () => {
              this.getDatalineList()
            }
          })
        }
      })
    },
    getlinetype(){
      getlinetypelist().then(({data}) => {
        this.ltlist = data;
      })
      this.linelineVisible=true;
    },

    getagencylist(){
      getagency().then(({data}) => {
        this.aglist = data.agency;
      })
    },

    addtripsbyid(id){
      getlinedetails(id).then(({data}) => {
        this.addtripsform.linename = data.name;
        this.addtripsform.transportLineId = id;
      })
      this.addtripsVisible = true;
    },
    addtripsSubmit(){
      let params = {
        'transportLineId': this.addtripsform.transportLineId,
        'name': this.addtripsform.name,
        'departureTime': this.addtripsform.departureTime,
        'period': this.addtripsform.period,
      }
      addtripsinfo(params).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '新增成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$refs['addtripsforms'].resetFields()
              this.addtripsVisible = false;
              this.getDatalineList()
            }
          })
        }
      })
    },
    gettripsbyid(id){
      gettripsinfo(id).then(({data}) => {
        this.updatetripsform.transportLineId = data.transportLineId;
        this.updatetripsform.id = data.id;
        this.updatetripsform.name = data.name;
        this.updatetripsform.departureTime = data.departureTime;
        this.updatetripsform.period = data.period;
        getlinedetails(data.transportLineId).then(({data}) => {
          this.updatetripsform.linename = data.name;
        })
      })

      this.updatetripsVisible = true;
    },
    updatatrips(){
      let params = {
        'id': this.updatetripsform.id,
        'transportLineId': this.updatetripsform.transportLineId,
        'name': this.updatetripsform.name,
        'departureTime': this.updatetripsform.departureTime,
        'period': this.updatetripsform.period,
      }
      updatetripsbyid(params).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '修改成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$refs['updatetripsforms'].resetFields()
              this.updatetripsVisible = false;
              this.getDatalineList()
            }
          })
        }
      })
    },

    deletetrips(id){
      deletetripsbyid(id).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '删除成功',
            type: 'error',
            duration: 1500,
            onClose: () => {
              this.getDatalineList()
            }
          })
        }
      })
    },
    getdriver(){
      getdriverinfos().then(({data}) => {
        this.driverlist = data;
      })
    },

    gettruck(){
      gettruckinfolist().then(({data}) => {
        this.trucklist = data.truck;
      })
    },

    maketrucks(id){
      gettripsinfo(id).then(({data}) => {
        this.truckform.transportTripsId = data.id;
        this.truckform.name = data.name;
        this.truckform.departureTime = data.departureTime;
        getlinedetails(data.transportLineId).then(({data}) => {
          this.truckform.linename = data.name;
        })
      })
      this.maketruckVisible = true;
      this.gettruck();
    },

    maketrucksubmit(){
      let params = {
        'truckslist': this.truckform.truckslist,
        'transportTripsId': this.truckform.transportTripsId,
      }
      maketrucks(params).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '修改成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$refs['updatetripsforms'].resetFields()
              this.maketruckVisible = false
              this.getDatalineList()
            }
          })
        }
      })
    },

    makedriver(id){
      gettripsinfo(id).then(({data}) => {
        this.truckform.id = data.id;
        this.truckform.name = data.name;
        this.truckform.departureTime = data.departureTime;
        getlinedetails(data.transportLineId).then(({data}) => {
          this.truckform.linename = data.name;
        })
      })
      gettruckdriverinfo(id).then(({data}) => {
        this.truckdriverDate = data;
      })
      this.makedriverVisible = true;
      this.getdriver();
      this.driverlist.forEach(v => {
        v.disabled = true
      })
    },
    updatetruckdriver(){
      document.getElementById("edit").setAttribute("hidden","hidden");
      document.getElementById("save").removeAttribute("hidden");
      this.driverlist.forEach(v => {
        v.disabled = false
      })
    },
    makedriversubmit(id){
      let params = {
        'id': id,
        'userId':this.makedriverform.userId,
      }
      maketruckdrivers(params).then(({data}) => {
        if (data && data.code == 0) {
          this.$message({
            message: '保存成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$refs['updatetripsforms'].resetFields()
              this.makedriverVisible = false;
              this.getDatalineList()
            }
          })
        }
      })
    },

    getbaiduditu(){
      this.mapVisible = true;
    },


  }
}

/*

*  */
</script>
